def count_sort(A, k):
    n = len(A)
    C = [0] * (k + 1)
    B = [None] * n
    for a in A: C[a] += 1
    for i in xrange(1, k + 1):
        C[i] += C[i - 1]
    for j in xrange(n-1, -1, -1):
        B[C[A[j]] - 1] = A[j]
        C[A[j]] -= 1
    print "C:", C
    return B

if __name__ == '__main__':
    A = [2,5,3,0,2,3,0,3]
    B = count_sort(A,10)
    print B
